package com.atguigu05._super.ex3;

public class CheckAccount extends Account{
    private double overdraft;//可透支的金额

    public CheckAccount(int id, double balance, double annuallnterestRate,double overdraft) {
        super(id, balance, annuallnterestRate);
        this.overdraft=overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    public void withdraw (double amount){
        if(getBalance()>=amount){
            super.withdraw(amount);
        }
        else{
            if(this.getOverdraft()>=(amount-super.getBalance())){
                overdraft-=amount-getBalance();
                super.withdraw(getBalance());

            }
            else {
                System.out.println("可透支的余额不足");
            }

        }
    }
}
